#include "to.h"

namespace YQ {

ImageData
toImageData (const Mat &img)
{
	return ImageData (img.data, img.cols, img.rows, img.channels());
}

ImageData
toImageData (const string &img_file) noexcept (false)
{
	return toImageData (toMat (img_file));
}

Mat
toMat (const ImageData &img)
{
	return Mat (img.height, img.width, CV_8UC (img.channels), img.data);
}

Mat
toMat (const string &img_file) noexcept (false)
{
	Mat img = imread (img_file, cv::ImreadModes::IMREAD_UNCHANGED);
	if (img.empty())
		throw  runtime_error ("无法打开图片" + img_file);
	return img;
}

vector<SeetaFaceInfo>
toVector (const SeetaFaceInfoArray &faces_info)
{
	vector<SeetaFaceInfo>faces;
	for (int i = 0; i < faces_info.size; ++i)
		faces.push_back (faces_info.data[i]);
	return faces;
}

cv::Rect
toCvRect (const SeetaRect &rect)
{
	return cv::Rect (rect.x, rect.y, rect.width, rect.height);
}

}